//
//  hostPopFunc.m
//  penzer
//
//  Created by caiyc on 2018/10/4.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "hostPopFunc.h"
#define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width
#define ALERT_HTIGHT 400
@interface hostPopFunc()<UIGestureRecognizerDelegate>
@property (nonatomic,strong) UIView *alertview;
@property (nonatomic,strong)UILabel *titleLab;
@property (nonatomic,strong)UILabel *messageLab;
@property (nonatomic,strong)UIButton *cancelBtn;
@property (nonatomic,strong)UIButton *otherBtn;
@property(nonatomic,strong)UIImageView *backImg;
@property(nonatomic,strong)UIImageView *left_Img;
@property(nonatomic,strong)UIImageView *right_Img;
@property(nonatomic,strong)UIButton *left_Btn;
@property(nonatomic,strong)UIButton *right_Btn;
@property(nonatomic,strong)UIView *examView;
@property(nonatomic,strong)UIButton *cofirm_Btn;
@property(nonatomic,strong)UIButton *close_Btn;
@end
@implementation hostPopFunc
-(instancetype)init{
    self = [super init];
    if(self){
        
        
        
        self.frame = [UIScreen mainScreen].bounds;
        
        self.alertview.frame = CGRectMake(0, screen_height-180, SCREEN_WIDTH, 180);
        [self.alertview addSubview:self.backImg];
        //  self.alertview.center = self.center;
        [self addSubview:self.alertview];
        NSArray *images = @[@"Group 15",@"Group 16",@"Group 17",@"退出"];
        NSArray *titles = @[@"分享直播",@"开启互动",@"关闭弹幕",@"关闭直播"];
        CGFloat imageWidth = screen_width/images.count;
        NSInteger imagewidth = 40;
        for(int i =0;i<images.count;i++){
            UIView *item_View = [[UIView alloc]initWithFrame:CGRectMake(imageWidth*i, 20, imageWidth, 100)];
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(imageWidth/2-imagewidth/2, 15, 40, 40)];
            imageView.image = [UIImage imageNamed:images[i]];
            [item_View addSubview:imageView];
            
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 70, imageWidth, 30)];
            title.textColor = [UIColor whiteColor];
            title.font = [UIFont systemFontOfSize:15];
            title.text = titles[i];
            title.tag = 1024+i;
            title.textAlignment = NSTextAlignmentCenter;
            [item_View addSubview:title];
            [self.alertview addSubview:item_View];
            
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(0, 0, imageWidth, 100);
            btn.tag = i;
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [item_View addSubview:btn];
            
            
        }
        UIButton *close_Btn = [UIButton buttonWithType:UIButtonTypeCustom];
        close_Btn.frame = CGRectMake(screen_width/2-20, 130, 40, 40);
        [close_Btn setImage:[UIImage imageNamed:@"关  闭"] forState:UIControlStateNormal];
        close_Btn.tag = 10;
        [close_Btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.alertview addSubview:close_Btn];
        
       
        
        
    }
    return self;
    
}
-(void)btnClick:(UIButton *)btn{
 
    if([self.delegate respondsToSelector:@selector(AlertView:clickedButtonAtIndex:Andtitle:)]){
        [self.delegate AlertView:self clickedButtonAtIndex:btn.tag Andtitle:@"关闭弹幕"];
      
    }
    [self dismissAlertView];
}
-(void)dismissAlertView{
    [UIView animateWithDuration:0.3 animations:^{
        [self removeFromSuperview];
    }];
}
-(UIView *)alertview
{
    if (_alertview == nil) {
        _alertview = [[UIView alloc] init];
        _alertview.backgroundColor = RGBA(0, 0, 0, .7);
        // _alertview.layer.cornerRadius=5.0;
        _alertview.layer.masksToBounds=YES;
        _alertview.userInteractionEnabled=YES;
    }
    return _alertview;
}
-(void)show:(BOOL)opendanmu andCollect:(BOOL)iscollect
{
    UILabel *danmu = (UILabel *)[self viewWithTag:1024+2];
    if(opendanmu==1){
        danmu.text = @"关闭弹幕";
    }else{
        danmu.text = @"开启弹幕";
    }
    self.backgroundColor = [UIColor clearColor];
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    CGAffineTransform transform = CGAffineTransformScale(CGAffineTransformIdentity,1.0,1.0);
    
    self.alertview.transform = CGAffineTransformScale(CGAffineTransformIdentity,0,0);
    // self.alertview.alpha = 0;
    [UIView animateWithDuration:0.3 delay:0.1 usingSpringWithDamping:0.5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveLinear animations:^{
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.4f];
        self.alertview.transform = transform;
        self.alertview.alpha = 1;
    } completion:^(BOOL finished) {
        
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
